package com.zzjson.controller;

import com.zzjson.domain.User;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : com.zzjson.controller</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年11月07日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
@RestController
public class UserController {
	@PostMapping("/user/save")
	public User save(@Valid @RequestBody User user) {
		return user;
	}

	@PostMapping("/user/save2")
	public User save2(@Valid @RequestBody User user) {
		//无论是断言还是api都会破坏程序的
		//APi调用的方式
		Assert.hasText(user.getName(), "名称不能为空");

		//JVM断言
		assert user.getId() <= 1000;

		return user;
	}
}